package util;
/***价格计算工具类***/

import java.math.BigDecimal;

public class bigDecimalUtil {
	/**
	 * 加法运算
	 * */
	public static BigDecimal add(double d1,double d2) {
		BigDecimal bd1 = new BigDecimal(String.valueOf(d1));
		BigDecimal bd2 = new BigDecimal(String.valueOf(d2));
		return bd1.add(bd2);
	}
	/**
	 * 减法运算
	 * */
	public static BigDecimal sub(double d1,double d2) {
		BigDecimal bd1 = new BigDecimal(String.valueOf(d1));
		BigDecimal bd2 = new BigDecimal(String.valueOf(d2));
		return bd1.subtract(bd2);
	}
	/**
	 * 乘法运算
	 * */
	public static BigDecimal mul(double d1,double d2) {
		BigDecimal bd1 = new BigDecimal(String.valueOf(d1));
		BigDecimal bd2 = new BigDecimal(String.valueOf(d2));
		return bd1.multiply(bd2);
	}
	/**
	 * 减法运算，保留2位小数，四舍五入
	 * */
	public static BigDecimal div(double d1,double d2) {
		BigDecimal bd1 = new BigDecimal(String.valueOf(d1));
		BigDecimal bd2 = new BigDecimal(String.valueOf(d2));
		return bd1.divide(bd2, 2, BigDecimal.ROUND_HALF_UP);
	}
}
